//
//  AboutProductViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS

#import "AboutProductViewController.h"
#import <SVProgressHUD.h>

@interface AboutProductViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UIImageView *product_img;

@property (nonatomic, strong) UIImageView *product_text;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UILabel *label_first;

@property (nonatomic, strong) UILabel *label_second;

@end

@implementation AboutProductViewController

#pragma mark
#pragma mark -- 懒加载
- (UIImageView *)product_text{
    if (nil== _product_text) {
        _product_text = [[UIImageView alloc] init];
    }
    return _product_text;
}

- (UIImageView *)product_img{
    if (nil == _product_img) {
        _product_img = [[UIImageView alloc] init];
    }
    return _product_img;
}

- (UITableView *)tableView{
    if (nil == _tableView) {
        _tableView = [[UITableView alloc] init];
    }
    return _tableView;
}

- (UILabel *)label_first{
    if (nil == _label_first) {
        _label_first = [[UILabel alloc] init];
    }
    return _label_first;
}

- (UILabel *)label_second{
    if (nil == _label_second) {
        _label_second = [[UILabel alloc] init];
    }
    return _label_second;
}

#pragma mark
#pragma mark -- viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

#pragma mark
#pragma mark -- 加载界面
- (void)setupUI {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.barTintColor = kThemeColor;
    
    self.title = @"关于产品";
    
    //设置图片
    self.product_img.image = [UIImage imageNamed:@"product_img_logo_nor.png"];
    
    self.product_text.image = [UIImage imageNamed:@"product_text_logo_nor.png"];
    
    [self.view addSubview:self.product_img];
    
    [self.view addSubview:self.product_text];
    
    //设置Label
    [self.label_first setFont:[UIFont systemFontOfSize:18]];
    
    [self.label_first setTextAlignment:NSTextAlignmentCenter];
    
    [self.label_first setTextColor:[UIColor colorWithRed:0.1373 green:0.6549 blue:0.945 alpha:1.0]];
    
    [self.label_first setText:@"version:  1.4.0"];
    
    [self.view addSubview:self.label_first];
    
    [self.label_second setFont:[UIFont systemFontOfSize:18]];
    
    [self.label_second setTextAlignment:NSTextAlignmentCenter];
    
    [self.label_second setTextColor:[UIColor colorWithRed:0.1373 green:0.6549 blue:0.945 alpha:1.0]];
    
    [self.label_second setText:@"用户交流:  4638375473"];
    
    [self.view addSubview:self.label_second];
    
    //设置tableview
    self.tableView.separatorColor = [UIColor colorWithRed:0.7843 green:0.7804 blue:0.8 alpha:1.0];
    
    //设置代理对象
    self.tableView.delegate = self;
    self.tableView.dataSource =self;
    
    // 给定预估行高
    self.tableView.estimatedRowHeight = 2;
    
    //自动估计行高
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    //注册cell
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cc"];
    
    [self.view addSubview:self.tableView];
    
#pragma
#pragma mark -- 设置约束
    [self.product_img mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(110);
    }];
    
    [self.product_text mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.product_img.mas_bottom);
    }];
    
    [self.label_first mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-50);
    }];
    
    [self.label_second mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.label_first).offset(-50);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self.view);
        make.height.equalTo(@50);
        make.left.right.equalTo(self.view);
    }];
}

#pragma mark
#pragma mark -- UITableViewDelegateUITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

#pragma mark
#pragma mark -- 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //设置cell内容
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cc"];
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    cell.textLabel.text = @"用户协议";
    
    cell.imageView.image = [UIImage imageNamed:@"product_img_icon_xieyi.png"];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

#pragma mark
#pragma mark -- 点击cell触发事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self showSuccessInfo];
}

#pragma mark
#pragma mark -- SVProgressHUD 设置弹窗效果
- (void)showSuccessInfo {
    
    UIImage *image = [UIImage imageNamed:@"SVProgressHUD.bundle/success"];
    
    [SVProgressHUD showImage:image status:@"打开用户协议"];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    
    //设置消失时间
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // time-consuming task
        [NSThread sleepForTimeInterval:1.5];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
    });
}

@end
